package com.vlong.town.controller.server.policy;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.policy.PolicyInfo;
import com.vlong.town.service.policy.PolicyInfoService;

/**
 * 政策规定Rest接口Controller
 * @author Assassin
 */
@RequestMapping("/rest/policy")
@RestController
public class PolicyRestController extends BaseController {

    // Fields

    @Autowired
    private PolicyInfoService policyInfoService;// 政策规定信息业务实现类

    /**
     * 查询政策信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<PolicyInfo>
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public List<PolicyInfo> list(
            @PathVariable(required=true, value="pageNo") Integer pageNo,
            @PathVariable(required=true, value="pageSize") Integer pageSize) {
        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("update_time DESC");
        List<PolicyInfo> policyInfoList = this.policyInfoService.queryList(null, null, null);
        return policyInfoList;
    }
    
    /**
     * 小程序
     * 查询政策信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<PolicyInfo>
     */
    @GetMapping("/listXcx")
    public List<PolicyInfo> listXcx(){
        List<PolicyInfo> policyInfoList = this.policyInfoService.queryList(null, null, null);
        for (PolicyInfo policyInfo : policyInfoList) {
        	Long createTime = policyInfo.getCreateTime();
        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
        	Date date = new  Date(createTime);
        	String format = sdf.format(date);
        	policyInfo.setCreateDate(format);
		}
        return policyInfoList;
    }
    
    /**
     * 查询政策详情
     * @param id 政策id
     * @return PolicyInfo
     */
    @GetMapping("/detail/{id}")
    public PolicyInfo detail(@PathVariable(required=true, value="id") Long id) {
    	return policyInfoService.queryById(id);
    }
    
    
    

}
